package ilog.gauges.percentgauge
{
  import factbook.Notifs;

  import flash.events.Event;

  import org.puremvc.as3.interfaces.INotification;
  import org.puremvc.as3.patterns.mediator.Mediator;

  public class PercentGaugeMediator extends Mediator
  {

    public function PercentGaugeMediator(viewComponent:Object=null)
    {
      super(NAME, viewComponent);
      percentGauge.addEventListener(PercentGauge.PERCENT_CHANGED_EVENT, onPercentChange);
    }

    override public function listNotificationInterests():Array
    {
      return [Notifs.PERCENTILE_COLOR_UPDATED];
    }

    override public function handleNotification(notification:INotification):void
    {
      switch(notification.getName())
      {
        case Notifs.PERCENTILE_COLOR_UPDATED:
          percentGauge.setColors(notification.getBody()as Array);
          break;
      }
    }

    private function onPercentChange(e:Event):void
    {
      sendNotification(Notifs.PERCENTILE_UPDATED, percentGauge.percentiles.concat([100]));
    }

    public function get percentGauge():PercentGauge
    {
      return PercentGauge(viewComponent);
    }
  }
}
